FROM python:3.9.16-bullseye as builder

WORKDIR /chatgpt
RUN sed -i "s/deb.debian.org/mirrors.tencent.com/g" /etc/apt/sources.list
RUN apt-get clean && apt-get update
RUN apt-get install inetutils-ping
RUN apt-get install unzip build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget git libbz2-dev -y

COPY ./certs.sh /chatgpt/certs.sh
RUN chmod +x /chatgpt/certs.sh && /chatgpt/certs.sh && cp -f /chatgpt/certs/server.crt /usr/local/share/ca-certificates/docker.crt
RUN mv /chatgpt/certs /etc/ssl/certs

RUN if ! git clone --depth=1 https://github.com/RockChinQ/QChatGPT.git QChatGPT; then echo "git clone failed"; exit 1;fi && cp -a ./QChatGPT/* ./ && rm -rf ./QChatGPT

RUN if [ ! -f requirements.txt ]; then echo "requirements.txt not found"; exit 1;fi
RUN if [ ! -f main.py ]; then echo "main.py not found"; exit 1;fi

RUN pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple && pip config set global.trusted-host mirrors.cloud.tencent.com
RUN pip install --upgrade pip
RUN pip3 install dulwich
RUN update-ca-certificates
RUN python3 -m pip install -r requirements.txt
CMD python3 main.py
